<template>
	<view class="scroll_tab_warp">
		<view class="tab_list">
			<view class="tab_cons">
				<view class="trans_box" :style="{transform: 'translateX('+100*tabIndex+'%)',width:(100/data.length)+'%'}">
					<view class="trans_button">
						
					</view>
				</view>
				<view class="tab_list_cons">
					<block v-for='(item,index) in data' :key="index">
						<view class="list_cons" :style="'width:'+(100/data.length)+'%'" :class="data[tabIndex].id==item.id?'list_cons_active':''" @click='changeTab(index)'>
							{{item.title}}
						</view>
						
					</block>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			value:{
				type:[Number,String],
				default:0
			},
			data:{
				type:Array,
				default:[]
			}
		},
		data(){
			return {
			}
		},
		computed:{
			tabIndex:{
				get(){
					return this.value
				},
				set(news){
					this.$emit('input',news)
				}
			}
		},
		methods:{
			changeTab(index){
				this.tabIndex = index
				let data = {
					index:index,
					id:this.data[index].id
				}
				this.$emit('change',data)
			}
		}
	}
</script>

<style>
	.scroll_tab_warp{
		width: 100%;
	}
	.tab_list{
		width: 100%;
		padding: 26px 32px 28px 32px;
		box-sizing: border-box;
	}
	.tab_cons{
		width: 100%;
		min-height: 68px;
		background: #FFFFFF;
		border: 0.5px solid #EBEBEB;
		border-radius: 16px;
		position: relative;
	}
	.trans_box{
		position: absolute;
		min-height: 68px;
		z-index: 5;
		transition: all .3s;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.trans_button{
		width: 104px;
		height: 56px;
		background: #FF6F32;
		box-shadow: inset -5px -4px 11px #FF9538;
		border-radius: 12px;
		margin: 0 auto;
	}
	.tab_list_cons{
		width: 100%;
		min-height: 68px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 82;
	}
	.list_cons{
		height: 56px;
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: bold;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #9695A8;
		font-size: 28px;
		line-height: 100%;
		/* identical to box height, or 14px */
		text-align: center;
	}
	.list_cons_active{
		color: #FFFFFF;
		transition: all .3s;
	}
</style>